package com.esri.android.map.popup;

import android.content.Context;
import android.net.Uri;
import android.os.Looper;
import android.widget.ListAdapter;
import com.esri.android.map.ags.ArcGISPopupInfo;
import com.esri.android.map.popup.ArcGISAttachmentsAdapter;
import com.esri.android.map.popup.ArcGISReadOnlyAttributesAdapter;
import com.esri.core.map.AttachmentInfo;
import java.io.File;
import java.util.List;

/* loaded from: classes.dex */
public class ArcGISAttachmentsView extends ArcGISAbstractMediaView implements AttachmentView, PopupEditable, PopupRefreshable {
    ArcGISAttachmentsAdapter b;
    protected ArcGISReadOnlyAttributesAdapter.FieldValueView mSpecialMessage;

    public ArcGISAttachmentsView(Context context, Popup popup) {
        super(context, popup, "Attachments");
        if (this.a.a == null) {
            setVisibility(8);
            return;
        }
        if (((this.a.a instanceof ArcGISPopupInfo) && !((ArcGISPopupInfo) this.a.a).isHasAttachments()) || !this.a.a.isShowAttachments()) {
            setVisibility(8);
        }
        ArcGISAttachmentsAdapter arcGISAttachmentsAdapter = new ArcGISAttachmentsAdapter(context, popup, null);
        this.b = arcGISAttachmentsAdapter;
        arcGISAttachmentsAdapter.a(new ArcGISAttachmentsAdapter.InternalAttachmentAdapterListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsView.1
            @Override // com.esri.android.map.popup.ArcGISAttachmentsAdapter.InternalAttachmentAdapterListener
            public void onAttachmentsRetrieved(List<AttachmentInfo> list) {
                if (list == null || list.size() < 1) {
                    ArcGISAttachmentsView.this.a();
                } else {
                    ArcGISAttachmentsView.this.a(true);
                }
            }

            @Override // com.esri.android.map.popup.ArcGISAttachmentsAdapter.InternalAttachmentAdapterListener
            public void onAttachmentRetrieving() {
                ArcGISAttachmentsView.this.displayMessage(Popup.getPopupString("ags_retrieving_attachments", "Searching...", ArcGISAttachmentsView.this.getContext()), true);
            }

            @Override // com.esri.android.map.popup.ArcGISAttachmentsAdapter.InternalAttachmentAdapterListener
            public void onAttachmentAdded(AttachmentInfo attachmentInfo) {
                if (ArcGISAttachmentsView.this.a.a.isShowAttachments() && 8 == ArcGISAttachmentsView.this.mGrid.getVisibility()) {
                    ArcGISAttachmentsView.this.a(true);
                }
            }

            @Override // com.esri.android.map.popup.ArcGISAttachmentsAdapter.InternalAttachmentAdapterListener
            public void onAttachmentRemoved(AttachmentInfo attachmentInfo) {
                if (ArcGISAttachmentsView.this.b.getCount() == 0) {
                    ArcGISAttachmentsView.this.a();
                }
            }
        });
        this.mGrid.setAdapter((ListAdapter) this.b);
        refresh();
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ArcGISAttachmentsAdapter arcGISAttachmentsAdapter = this.b;
        if (arcGISAttachmentsAdapter == null || !arcGISAttachmentsAdapter.a()) {
            return;
        }
        a();
    }

    protected void displayMessage(final String str, final boolean z) {
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            a(str, z);
        } else {
            post(new Runnable() { // from class: com.esri.android.map.popup.ArcGISAttachmentsView.2
                @Override // java.lang.Runnable
                public void run() {
                    ArcGISAttachmentsView.this.a(str, z);
                }
            });
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a(String str, boolean z) {
        if (this.mSpecialMessage == null) {
            ArcGISReadOnlyAttributesAdapter.FieldValueView fieldValueView = new ArcGISReadOnlyAttributesAdapter.FieldValueView(getContext(), str, (ArcGISPopupStyle) this.a.getLayout().getStyle());
            this.mSpecialMessage = fieldValueView;
            addView(fieldValueView);
        }
        this.mSpecialMessage.setText(str);
        this.mSpecialMessage.setVisibility(0);
        this.mGrid.setVisibility(z ? 8 : 0);
    }

    void a(final boolean z) {
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            b(z);
        } else {
            post(new Runnable() { // from class: com.esri.android.map.popup.ArcGISAttachmentsView.3
                @Override // java.lang.Runnable
                public void run() {
                    ArcGISAttachmentsView.this.b(z);
                }
            });
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void b(boolean z) {
        ArcGISReadOnlyAttributesAdapter.FieldValueView fieldValueView = this.mSpecialMessage;
        if (fieldValueView != null) {
            removeView(fieldValueView);
            this.mSpecialMessage = null;
        }
        if (z) {
            this.mGrid.setVisibility(0);
        }
    }

    @Override // com.esri.android.map.popup.PopupRefreshable
    public void refresh() {
        if (this.a.a == null) {
            return;
        }
        this.mGrid.postInvalidate();
    }

    @Override // com.esri.android.map.popup.PopupEditable
    public void setEditMode(boolean z) {
        if (this.a.a == null) {
            return;
        }
        if (z && !this.a.a.isShowAttachments() && (this.a.a instanceof ArcGISPopupInfo) && ((ArcGISPopupInfo) this.a.a).isHasAttachments()) {
            setVisibility(0);
        } else if (((this.a.a instanceof ArcGISPopupInfo) && !((ArcGISPopupInfo) this.a.a).isHasAttachments()) || !this.a.a.isShowAttachments()) {
            setVisibility(8);
        }
        ArcGISAttachmentsAdapter arcGISAttachmentsAdapter = this.b;
        if (arcGISAttachmentsAdapter != null) {
            arcGISAttachmentsAdapter.setEditMode(z);
        }
    }

    @Override // com.esri.android.map.popup.AttachmentView
    public List<File> getAddedAttachments() {
        ArcGISAttachmentsAdapter arcGISAttachmentsAdapter = this.b;
        if (arcGISAttachmentsAdapter != null) {
            return arcGISAttachmentsAdapter.c();
        }
        return null;
    }

    @Override // com.esri.android.map.popup.AttachmentView
    public List<Integer> getDeletedAttachmentIDs() {
        ArcGISAttachmentsAdapter arcGISAttachmentsAdapter = this.b;
        if (arcGISAttachmentsAdapter != null) {
            return arcGISAttachmentsAdapter.d();
        }
        return null;
    }

    @Override // com.esri.android.map.popup.AttachmentView
    public void addAttachment(Uri uri) {
        ArcGISAttachmentsAdapter arcGISAttachmentsAdapter = this.b;
        if (arcGISAttachmentsAdapter != null) {
            arcGISAttachmentsAdapter.a(uri);
        }
    }

    @Override // android.widget.LinearLayout, android.view.View
    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        this.b.setColumnWidth(this.mAdjustedColumnWidth);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a() {
        displayMessage(Popup.getPopupString("ags_no_attachments_found", "No attachments found", getContext()), true);
    }
}
